package property.service.impl;

import org.apache.ibatis.session.SqlSession;
import property.mapper.NoticeMapper;
import property.pojo.Notice;
import property.service.NoticeService;
import property.utils.mapper.MyBatisUtil;

public class NoticeServiceImpl implements NoticeService {

    @Override
    public int addNotice(Notice notice) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        NoticeMapper mapper = sqlSession.getMapper(NoticeMapper.class);
        int i = mapper.insertSelective(notice);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int deleteNotice(Integer id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        NoticeMapper mapper = sqlSession.getMapper(NoticeMapper.class);
        int i = mapper.deleteByPrimaryKey(id);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateNotice(Notice notice) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        NoticeMapper mapper = sqlSession.getMapper(NoticeMapper.class);
        int i = mapper.updateByPrimaryKeySelective(notice);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }


}
